/*
package com.fbt.andon.tool;

import com.fbt.andon.domain.BoardStation;
import com.sun.xml.internal.messaging.saaj.soap.Envelope;


import java.io.IOException;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.TimeoutException;

public class Direct {

    public String host;
    public String userName;
    public String passWord;
    public int port;
    public String virtualHost;

    public Direct(String host, String userName, String passWord, int port, String virtualHost) {
        this.host = host;
        this.userName = userName;
        this.passWord = passWord;
        this.port = port;
        this.virtualHost = virtualHost;
    }


    public Connection connection() throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(host);
        factory.setUsername(userName);
        factory.setPassword(passWord);
        factory.setPort(port);
        factory.setVirtualHost(virtualHost);
        return factory.newConnection();
    }

    */
/*关闭方法*//*

//    public void close(Connection connection, Channel channel) {
//        try {
//            if (null != channel) {
//                channel.close();
//            }
//            if (null != connection) {
//                connection.close();
//            }
//        } catch (Exception e) {
//            System.out.println(">>>>>>关闭RabbitMq的connection或channel发生异常>>>>>>");
//        }
//    }


    */
/*生产者*//*

    //        异步发布确认
    public void PublishAckMassage(String exchangeName, String route, String msg) throws IOException, TimeoutException {
        Connection connection = this.connection();
        //获取通道
        Channel channel = connection.createChannel();

        // 开启发布确认(默认是不开启的)
        channel.confirmSelect();
        */
/*
         * 线程有序的一个哈希表，适用于高并发的情况下
         * 1，轻松的将消息与序号进行关联
         * 2，轻松批量删除条目，只要给到序号
         * 3，支持高并发
         * *//*

        ConcurrentSkipListMap<Long, String> outAck = new ConcurrentSkipListMap<>();
        //消息监听器，监听哪些消息成功了，哪些消息失败了
        // 消息成功回调函数
        ConfirmCallback ackCallback = (deliveryTag, multiple) -> {
            //删除确认的消息
            if (multiple) {
                //批量确认
                ConcurrentNavigableMap<Long, String> confirmed = outAck.headMap(deliveryTag);
                confirmed.clear();
            } else {
                //单个确认
                outAck.remove(deliveryTag);
            }
//            System.out.println("消息投递成功编号为:"+deliveryTag);
        };
        */
/*  消息失败回调函数
         * 1,消息的标记
         * 2，是否为批量确认
         * *//*

        ConfirmCallback nackCallback = (deliveryTag, multiple) -> {
            //打印一下未确认的消息
            String nackMassage = outAck.get(deliveryTag);
            System.out.println("标记是" + deliveryTag + "未确认的消息是" + nackMassage);
            channel.basicPublish(exchangeName, route, null, nackMassage.getBytes());
        };
//        异步监听
        channel.addConfirmListener(ackCallback, nackCallback);
        //消息发布
//        for (int i = 0; i < 1000 ; i++) {
        //记录消息到outAck容器
        outAck.put(channel.getNextPublishSeqNo(), msg);
        //发送消息
        channel.basicPublish(exchangeName, route, null, msg.getBytes());
//        }
        channel.close();
        connection.close();
    }


    */
/*声名队列和交换机*//*

    public void bindingQueue(String exchangeName, String queueName, String route) throws IOException, TimeoutException {
        Connection connection = this.connection();
        Channel channel = connection.createChannel();
        //声明交换机名称
        channel.exchangeDeclare(exchangeName, "direct");
        channel.queueDeclare(queueName, true, false, false, null);
        // 队列与交换机绑定1.队列名称 2.交换机名称 3.路由规则
        channel.queueBind(queueName, exchangeName, route);
        channel.close();
        connection.close();
    }

    */
/*消费者*//*

    public BoardStation Consume(String queueName) throws IOException, TimeoutException {
        BoardStation boardStation = new BoardStation();
        Connection connection = this.connection();
        Channel channel = connection.createChannel();
        DefaultConsumer consumer = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
                    throws IOException {

                String msg = new String(body, "UTF-8");
                System.out.println("消费者获取生产者消息：<" + msg + ">");
            }
        };

        //消费那个队列中的信息
        channel.basicConsume(queueName, true, consumer);
        return boardStation;
    }


}






*/
